package com.fast.alden.admin.service.impl;

import com.fast.alden.admin.service.SysDepartmentService;
import com.fast.alden.common.service.impl.BaseTreeNodeEntityServiceImpl;
import com.fast.alden.data.model.SysDepartment;
import com.fast.alden.data.repo.SysDepartmentRepository;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.Comparator;
import java.util.List;

@Service
public class SysDepartmentServiceImpl extends BaseTreeNodeEntityServiceImpl<SysDepartment, SysDepartmentRepository> implements SysDepartmentService {
    @Resource
    private SysDepartmentRepository repository;

    @Override
    protected Class<SysDepartment> getEClass() {
        return SysDepartment.class;
    }

    @Override
    protected SysDepartmentRepository getRepository() {
        return repository;
    }

    @Override
    public List<SysDepartment> tree() {
        List<SysDepartment> list = this.list();
        list.sort(Comparator.comparing(SysDepartment::getOrderNo, Comparator.nullsLast(Comparator.naturalOrder())));
        return buildTreeList(list);
    }
}
